package my2Cents.tools;

import my2Cents.properties.Property;
import my2Cents.properties.Slider;
import net.phys2d.raw.Body;
import net.phys2d.raw.Joint;
import net.phys2d.raw.SpringJoint;

public class SpringTool extends AbstractConstraintMaker {
	private float springy = 60;
	private float extraLength;
	
	public SpringTool() {
		setName("Spring");
		Property p = new Slider("Elasticity",60,0,200,20,false) {
			private static final long serialVersionUID = 1L;

			public void valueChanged(int value) {
				springy = value;
			}
		};
		this.addProperty(p);
		
		Property p2 = new Slider("Extra Length",0,-200,200,50,true) {
			private static final long serialVersionUID = 1L;

			public void valueChanged(int value) {
				extraLength = value;
			}
		};
		this.addProperty(p2);
	}
	
	protected Joint createConstraint(Body b1, Body b2) {
		float len = start.distance(end);
		SpringJoint j = new SpringJoint(b1,b2,start,end);
		j.setCompressedSpringConst(springy);
		j.setStretchedSpringConst(springy);
		j.setSpringSize(len + extraLength);
		j.setMaxSpringSize(100000.0f); //BWAHAHAH
		return j;
	}
}
